<template>
  <div ref="companyNews" class="companyNews">
    <div v-if="total>0" class="autoArea">
      <div v-for="(item, index) in companyNewsList" :key="index" class="company-news-item">
        <div class="company-news-content">
          <div class="name" @click="openNews(item)">{{ item.newTitle }}
            <span v-if="item.emotion=='-1'" style="color: #FF5722">负面</span>
            <span v-else-if="item.emotion=='1'" style="color: #009688">正面</span>
            <span v-else-if="item.emotion=='0'" style="color: #31BDEC">中性</span>
          </div>
          <template v-for=" (row,index) in item.companyNewsTagsList">
            <el-tag
              :key="index"
              class="rim"
              size="mini"
              effect="plain"
              type="primary"
            >{{ row.tags }}</el-tag>
          </template>
          <div v-if="item.abstracts" class="abstracts">{{ item.abstracts }}</div>
          <div class="infos">
            <span v-if="item.newSource" class="source">{{ $t('来源') }}：{{ item.newSource }}</span>
            <span v-if="item.newTime" class="time">{{ $t('发布时间') }}：{{ parseTime(item.newTime) }}</span>
          </div>
        </div>
      </div>
    </div>
    <pagination
      v-show="total>0"
      class="dealPage"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div v-if="total === 0" class="noneData">
      <div>
        <svg-icon icon-class="none" class-name="none-icon" />
        <p>{{ $t('暂无数据') }}</p>
      </div>
    </div>
  </div>
</template>
<script>
  import { listCompanyNews } from '@/api/company/news/companyNews'
  export default {
    name: 'CompanyNewsInfo',
    props: {
      // 公司ID
      bussId: {
        type: String,
        required: true
      }
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 新闻信息表格数据
        companyNewsList: [],
        // 查询参数
        queryParams: {
          companyId: this.bussId,
          newTitle: undefined,
          newSource: undefined,
          newTime: undefined,
          pageNum: 1,
          pageSize: 10
        },
        // 表单参数
        form: {},
        color: ['', 'success', 'info', 'warning', 'danger']
      }
    },
    mounted() {
      this.getList()
    },
    methods: {
      /** 查询新闻信息列表 */
      getList() {
        this.loading = true
        this.queryParams.companyId = this.bussId
        listCompanyNews(this.queryParams).then(response => {
          this.companyNewsList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      openNews(row) {
        if (row.newUrl.indexOf('http://') !== -1) {
          window.open(row.newUrl)
        } else if (row.newUrl.indexOf('https://') !== -1) {
          window.open(row.newUrl)
        } else {
          window.open('http://' + row.newUrl)
        }
      },
        randumColor() {
        const a = Math.random()
        const b = a * 5
        // 向下取整
        const c = Math.floor(b)// 向下取整
        return this.color[c]
    }
    }
  }
</script>
<style scoped>
.rim{
  margin: 0px 4px 4px 4px;
}
</style>
